#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/8 17:37
# @Author  : jeff
# @FileName: task_vo
from pydantic import BaseModel, validator
from src.vo.exception_vo import ValidationError


class TaskVo(BaseModel):
    """
    Scheduled task data verification model
    """
    cron_time: str
    method_name: str
    module_name: str

    @validator('cron_time')
    def cron_time_length(cls, v):
        if len(v) < 1 or len(v) > 20:
            raise ValidationError('cron_time length must be between 1 and 20')
        return v

    @validator('method_name')
    def method_name_length(cls, v):
        if len(v) < 2 or len(v) > 20:
            raise ValidationError('method_name length must be between 1 and 20')
        return v


class TaskVoRes(BaseModel):
    """
    Create a scheduled task to return the data model
    """
    cron_time: str
    method_name: str
    module_name: str
    task_id: int
